package com.csdj.rest.config;

import com.csdj.middleware.RedisService;
import com.csdj.rest.inteceptor.LangInterceptor;
import com.csdj.rest.inteceptor.LoginInteceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    private Logger log = LoggerFactory.getLogger("webconfig");
    @Resource
    private RedisService redisService;

//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/**","classpath:/static");
//    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        final LoginInteceptor loginInteceptor = new LoginInteceptor(redisService);
        loginInteceptor.setInvalid(false);
        registry.addInterceptor(loginInteceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/reg","/user/password","/test/**","/ws/**");
        registry.addInterceptor(new LangInterceptor())
                .addPathPatterns("/**");
    }
}
